
package jannex.internal;

import jannex.Builder;
import jannex.Jannex;
import jannex.JannexException;
import jannex.sql.extensions.TypedResultSetImpl;
import jannex.label.LabelMap;
import jannex.mapping.ResultSetHandler;
import jannex.sql.*;

import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.*;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;

public class ResultSubSet implements JxResultSet {

    private final Jannex jannex;
    private final JxResultSet resultSet;
    private final int[] columns;
    private final LabelMap<Integer> labelIndex;

    public static JxResultSet forColumnIndexes(JxResultSet resultSet, Jannex jannex, int... indexes) {
        JxResultSetMetaData metaData = resultSet.getMetaData();
        LabelMap.Builder<Integer> map = LabelMap.builder();
        for (int index : indexes) {
            String label = metaData.getColumnLabel(index);
            map.put(label, index);
        }
        return new ResultSubSet(resultSet, jannex, indexes, map.build());
    }

    public static ResultSubSet forTableName(JxResultSet resultSet, Jannex jannex, String tableName) {
        JxResultSetMetaData metaData = resultSet.getMetaData();
        List<Integer> matchedColumns = new ArrayList<>();
        LabelMap.Builder<Integer> map = LabelMap.builder();
        for (int i = 1; i <= metaData.getColumnCount(); i++) {
            String tableI = metaData.getTableName(i);
            if (tableI.equalsIgnoreCase(tableName)) {
                matchedColumns.add(i);
                map.put(metaData.getColumnLabel(i), i);
            }
        }
        int[] columns = new int[matchedColumns.size()];
        for (int i = 0; i < matchedColumns.size(); i++) {
            columns[i] = matchedColumns.get(i);
        }
        return new ResultSubSet(resultSet, jannex, columns, map.build());
    }

    private ResultSubSet(JxResultSet resultSet, Jannex jannex, int[] columns, LabelMap<Integer> labelIndex) {
        this.resultSet = resultSet;
        this.jannex = jannex;
        this.columns = columns;
        this.labelIndex = labelIndex;
    }

    @Override
    public <E> TypedResultSet<E> as(Class<E> elementClass) {
        return new TypedResultSetImpl<>(this, jannex, jannex.getHandler(elementClass));
    }

    @Override
    public <E> TypedResultSet<E> as(ResultSetHandler<E> handler) {
        return new TypedResultSetImpl<>(this, jannex, handler);
    }

    @Override
    public JxResultSetMetaData getMetaData() {
        return new ResultSubSetMetaData(resultSet.getMetaData(), columns, labelIndex);
    }

    @Override
    public <E> Fetcher<E> fetch(final Class<E> elementClass) {
        return new Fetcher<>(new Builder<TypedResultSet<E>>() {
            @Override
            public TypedResultSet<E> build() {
                return as(elementClass);
            }
        });
    }

    @Override
    public JxResultSet subSetFromTable(String tableName) {
        return forTableName(resultSet, jannex, tableName);
    }

    @Override
    public JxResultSet subSetFrom(int... columnIndexes) {
        return forColumnIndexes(this, jannex, columnIndexes);
    }

    @Override
    public boolean next() throws JannexException {
        return resultSet.next();
    }

    @Override
    public void close() throws JannexException {
        resultSet.close();
    }

    @Override
    public boolean wasNull() throws JannexException {
        return resultSet.wasNull();
    }

    @Override
    public boolean isWrapperFor(Class<?> iface) {
        return iface.equals(JxResultSet.class) || resultSet.isWrapperFor(iface);
    }

    @SuppressWarnings("unchecked")
    @Override
    public <T> T unwrap(Class<T> iface) {
        if (iface.equals(JxResultSet.class)) {
            return (T) resultSet;
        }
        return resultSet.unwrap(iface);
    }

    @Override
    public int findColumn(String columnLabel) {
        Integer ix = labelIndex.get(columnLabel);
        if (ix == null) {
            return -1;
        }
        return ix;
    }

    @Override
    public String getString(int columnIndex) {
        return resultSet.getString(columns[columnIndex-1]);
    }

    @Override
    public boolean getBoolean(int columnIndex) {
        return resultSet.getBoolean(columns[columnIndex-1]);
    }

    @Override
    public byte getByte(int columnIndex) {
        return resultSet.getByte(columns[columnIndex-1]);
    }

    @Override
    public short getShort(int columnIndex) {
        return resultSet.getShort(columns[columnIndex-1]);
    }

    @Override
    public int getInt(int columnIndex) {
        return resultSet.getInt(columns[columnIndex-1]);
    }

    @Override
    public long getLong(int columnIndex) {
        return resultSet.getLong(columns[columnIndex-1]);
    }

    @Override
    public float getFloat(int columnIndex) {
        return resultSet.getFloat(columns[columnIndex-1]);
    }

    @Override
    public double getDouble(int columnIndex) {
        return resultSet.getDouble(columns[columnIndex-1]);
    }

    @Override
    @Deprecated
    @SuppressWarnings("deprecation")
    public BigDecimal getBigDecimal(int columnIndex, int scale) {
        return resultSet.getBigDecimal(columns[columnIndex-1], scale);
    }

    @Override
    public byte[] getBytes(int columnIndex) {
        return resultSet.getBytes(columns[columnIndex-1]);
    }

    @Override
    public Date getDate(int columnIndex) {
        return resultSet.getDate(columns[columnIndex-1]);
    }

    @Override
    public Time getTime(int columnIndex) {
        return resultSet.getTime(columns[columnIndex-1]);
    }

    @Override
    public Timestamp getTimestamp(int columnIndex) {
        return resultSet.getTimestamp(columns[columnIndex-1]);
    }

    @Override
    public InputStream getAsciiStream(int columnIndex) {
        return resultSet.getAsciiStream(columns[columnIndex-1]);
    }

    @Override
    public void updateAsciiStream(int columnIndex, InputStream x) {
        resultSet.updateAsciiStream(columns[columnIndex-1], x);
    }

    @Override
    public void updateBinaryStream(int columnIndex, InputStream x) {
        resultSet.updateBinaryStream(columns[columnIndex-1], x);
    }

    @Override
    public void updateCharacterStream(int columnIndex, Reader x) {
        resultSet.updateCharacterStream(columns[columnIndex-1], x);
    }

    @Override
    public void updateAsciiStream(String columnLabel, InputStream x) {
        resultSet.updateAsciiStream(findColumn(columnLabel), x);
    }

    @Override
    public void updateBinaryStream(String columnLabel, InputStream x) {
        resultSet.updateBinaryStream(findColumn(columnLabel), x);
    }

    @Override
    public void updateCharacterStream(String columnLabel, Reader reader) {
        resultSet.updateCharacterStream(findColumn(columnLabel), reader);
    }

    @Override
    public void updateBlob(int columnIndex, InputStream inputStream) {
        resultSet.updateBlob(columns[columnIndex-1], inputStream);
    }

    @Override
    public void updateBlob(String columnLabel, InputStream inputStream) {
        resultSet.updateBlob(findColumn(columnLabel), inputStream);
    }

    @Override
    public void updateClob(int columnIndex, Reader reader) {
        resultSet.updateClob(columns[columnIndex-1], reader);
    }

    @Override
    public void updateClob(String columnLabel, Reader reader) {
        resultSet.updateClob(findColumn(columnLabel), reader);
    }

    @Override
    public void updateNClob(int columnIndex, Reader reader) {
        resultSet.updateNClob(columns[columnIndex-1], reader);
    }

    @Override
    public void updateNClob(String columnLabel, Reader reader) {
        resultSet.updateNClob(findColumn(columnLabel), reader);
    }

    @Override
    public <T> T getObject(int columnIndex, Class<T> type) {
        return resultSet.getObject(columns[columnIndex-1], type);
    }

    @Override
    public <T> T getObject(String columnLabel, Class<T> type) {
        return resultSet.getObject(findColumn(columnLabel), type);
    }

    @Override
    public void updateSQLXML(int columnIndex, SQLXML xmlObject) {
        resultSet.updateSQLXML(columns[columnIndex-1], xmlObject);
    }

    @Override
    public void updateSQLXML(String columnLabel, SQLXML xmlObject) {
        resultSet.updateSQLXML(findColumn(columnLabel), xmlObject);
    }

    @Override
    public String getNString(int columnIndex) {
        return resultSet.getNString(columns[columnIndex-1]);
    }

    @Override
    public String getNString(String columnLabel) {
        return resultSet.getNString(findColumn(columnLabel));
    }

    @Override
    public Reader getNCharacterStream(int columnIndex) {
        return resultSet.getNCharacterStream(columns[columnIndex-1]);
    }

    @Override
    public Reader getNCharacterStream(String columnLabel) {
        return resultSet.getNCharacterStream(findColumn(columnLabel));
    }

    @Override
    public void updateNCharacterStream(int columnIndex, Reader x, long length) {
        resultSet.updateNCharacterStream(columns[columnIndex-1], x, length);
    }

    @Override
    public void updateNCharacterStream(String columnLabel, Reader reader, long length) {
        resultSet.updateNCharacterStream(findColumn(columnLabel), reader, length);
    }

    @Override
    public void updateAsciiStream(int columnIndex, InputStream x, long length) {
        resultSet.updateAsciiStream(columns[columnIndex-1], x, length);
    }

    @Override
    public void updateBinaryStream(int columnIndex, InputStream x, long length) {
        resultSet.updateBinaryStream(columns[columnIndex-1], x, length);
    }

    @Override
    public void updateCharacterStream(int columnIndex, Reader x, long length) {
        resultSet.updateCharacterStream(columns[columnIndex-1], x, length);
    }

    @Override
    public void updateAsciiStream(String columnLabel, InputStream x, long length) {
        resultSet.updateAsciiStream(findColumn(columnLabel), x, length);
    }

    @Override
    public void updateBinaryStream(String columnLabel, InputStream x, long length) {
        resultSet.updateBinaryStream(findColumn(columnLabel), x, length);
    }

    @Override
    public void updateCharacterStream(String columnLabel, Reader reader, long length) {
        resultSet.updateCharacterStream(findColumn(columnLabel), reader, length);
    }

    @Override
    public void updateBlob(int columnIndex, InputStream inputStream, long length) {
        resultSet.updateBlob(columns[columnIndex-1], inputStream, length);
    }

    @Override
    public void updateBlob(String columnLabel, InputStream inputStream, long length) {
        resultSet.updateBlob(findColumn(columnLabel), inputStream, length);
    }

    @Override
    public void updateClob(int columnIndex, Reader reader, long length) {
        resultSet.updateClob(columns[columnIndex-1], reader, length);
    }

    @Override
    public void updateClob(String columnLabel, Reader reader, long length) {
        resultSet.updateClob(findColumn(columnLabel), reader, length);
    }

    @Override
    public void updateNClob(int columnIndex, Reader reader, long length) {
        resultSet.updateNClob(columns[columnIndex-1], reader, length);
    }

    @Override
    public void updateNClob(String columnLabel, Reader reader, long length) {
        resultSet.updateNClob(findColumn(columnLabel), reader, length);
    }

    @Override
    public void updateNCharacterStream(int columnIndex, Reader x) {
        resultSet.updateNCharacterStream(columns[columnIndex-1], x);
    }

    @Override
    public void updateNCharacterStream(String columnLabel, Reader reader) {
        resultSet.updateNCharacterStream(findColumn(columnLabel), reader);
    }

    @Override
    public void updateRef(int columnIndex, Ref x) {
        resultSet.updateRef(columns[columnIndex-1], x);
    }

    @Override
    public void updateRef(String columnLabel, Ref x) {
        resultSet.updateRef(findColumn(columnLabel), x);
    }

    @Override
    public void updateBlob(int columnIndex, Blob x) {
        resultSet.updateBlob(columns[columnIndex-1], x);
    }

    @Override
    public void updateBlob(String columnLabel, Blob x) {
        resultSet.updateBlob(findColumn(columnLabel), x);
    }

    @Override
    public void updateClob(int columnIndex, Clob x) {
        resultSet.updateClob(columns[columnIndex-1], x);
    }

    @Override
    public void updateClob(String columnLabel, Clob x) {
        resultSet.updateClob(findColumn(columnLabel), x);
    }

    @Override
    public void updateArray(int columnIndex, Array x) {
        resultSet.updateArray(columns[columnIndex-1], x);
    }

    @Override
    public void updateArray(String columnLabel, Array x) {
        resultSet.updateArray(findColumn(columnLabel), x);
    }

    @Override
    public RowId getRowId(int columnIndex) {
        return resultSet.getRowId(columns[columnIndex-1]);
    }

    @Override
    public RowId getRowId(String columnLabel) {
        return resultSet.getRowId(findColumn(columnLabel));
    }

    @Override
    public void updateRowId(int columnIndex, RowId x) {
        resultSet.updateRowId(columns[columnIndex-1], x);
    }

    @Override
    public void updateRowId(String columnLabel, RowId x) {
        resultSet.updateRowId(findColumn(columnLabel), x);
    }

    @Override
    public int getHoldability() throws JannexException {
        return resultSet.getHoldability();
    }

    @Override
    public boolean isClosed() throws JannexException {
        return resultSet.isClosed();
    }

    @Override
    public void updateNString(int columnIndex, String nString) {
        resultSet.updateNString(columns[columnIndex-1], nString);
    }

    @Override
    public void updateNString(String columnLabel, String nString) {
        resultSet.updateNString(findColumn(columnLabel), nString);
    }

    @Override
    public void updateNClob(int columnIndex, NClob nClob) {
        resultSet.updateNClob(columns[columnIndex-1], nClob);
    }

    @Override
    public void updateNClob(String columnLabel, NClob nClob) {
        resultSet.updateNClob(findColumn(columnLabel), nClob);
    }

    @Override
    public JxNClob getNClob(int columnIndex) {
        return resultSet.getNClob(columns[columnIndex-1]);
    }

    @Override
    public JxNClob getNClob(String columnLabel) {
        return resultSet.getNClob(findColumn(columnLabel));
    }

    @Override
    public JxSQLXML getSQLXML(int columnIndex) {
        return resultSet.getSQLXML(columns[columnIndex-1]);
    }

    @Override
    public JxSQLXML getSQLXML(String columnLabel) {
        return resultSet.getSQLXML(findColumn(columnLabel));
    }

    @Override
    public Object getObject(int columnIndex, Map<String, Class<?>> map) {
        return resultSet.getObject(columns[columnIndex-1], map);
    }

    @Override
    public JxRef getRef(int columnIndex) {
        return resultSet.getRef(columns[columnIndex-1]);
    }

    @Override
    public JxBlob getBlob(int columnIndex) {
        return resultSet.getBlob(columns[columnIndex-1]);
    }

    @Override
    public JxClob getClob(int columnIndex) {
        return resultSet.getClob(columns[columnIndex-1]);
    }

    @Override
    public JxArray getArray(int columnIndex) {
        return resultSet.getArray(columns[columnIndex-1]);
    }

    @Override
    public Object getObject(String columnLabel, Map<String, Class<?>> map) {
        return resultSet.getObject(findColumn(columnLabel), map);
    }

    @Override
    public JxRef getRef(String columnLabel) {
        return resultSet.getRef(findColumn(columnLabel));
    }

    @Override
    public JxBlob getBlob(String columnLabel) {
        return resultSet.getBlob(findColumn(columnLabel));
    }

    @Override
    public JxClob getClob(String columnLabel) {
        return resultSet.getClob(findColumn(columnLabel));
    }

    @Override
    public JxArray getArray(String columnLabel) {
        return resultSet.getArray(findColumn(columnLabel));
    }

    @Override
    public Date getDate(int columnIndex, Calendar cal) {
        return resultSet.getDate(columns[columnIndex-1], cal);
    }

    @Override
    public Date getDate(String columnLabel, Calendar cal) {
        return resultSet.getDate(findColumn(columnLabel), cal);
    }

    @Override
    public Time getTime(int columnIndex, Calendar cal) {
        return resultSet.getTime(columns[columnIndex-1], cal);
    }

    @Override
    public Time getTime(String columnLabel, Calendar cal) {
        return resultSet.getTime(findColumn(columnLabel), cal);
    }

    @Override
    public Timestamp getTimestamp(int columnIndex, Calendar cal) {
        return resultSet.getTimestamp(columns[columnIndex-1], cal);
    }

    @Override
    public Timestamp getTimestamp(String columnLabel, Calendar cal) {
        return resultSet.getTimestamp(findColumn(columnLabel), cal);
    }

    @Override
    public URL getURL(int columnIndex) {
        return resultSet.getURL(columns[columnIndex-1]);
    }

    @Override
    public URL getURL(String columnLabel) {
        return resultSet.getURL(findColumn(columnLabel));
    }

    @Override
    public void updateBoolean(String columnLabel, boolean x) {
        resultSet.updateBoolean(findColumn(columnLabel), x);
    }

    @Override
    public void updateByte(String columnLabel, byte x) {
        resultSet.updateByte(findColumn(columnLabel), x);
    }

    @Override
    public void updateShort(String columnLabel, short x) {
        resultSet.updateShort(findColumn(columnLabel), x);
    }

    @Override
    public void updateInt(String columnLabel, int x) {
        resultSet.updateInt(findColumn(columnLabel), x);
    }

    @Override
    public void updateLong(String columnLabel, long x) {
        resultSet.updateLong(findColumn(columnLabel), x);
    }

    @Override
    public void updateFloat(String columnLabel, float x) {
        resultSet.updateFloat(findColumn(columnLabel), x);
    }

    @Override
    public void updateDouble(String columnLabel, double x) {
        resultSet.updateDouble(findColumn(columnLabel), x);
    }

    @Override
    public void updateBigDecimal(String columnLabel, BigDecimal x) {
        resultSet.updateBigDecimal(findColumn(columnLabel), x);
    }

    @Override
    public void updateString(String columnLabel, String x) {
        resultSet.updateString(findColumn(columnLabel), x);
    }

    @Override
    public void updateBytes(String columnLabel, byte[] x) {
        resultSet.updateBytes(findColumn(columnLabel), x);
    }

    @Override
    public void updateDate(String columnLabel, Date x) {
        resultSet.updateDate(findColumn(columnLabel), x);
    }

    @Override
    public void updateTime(String columnLabel, Time x) {
        resultSet.updateTime(findColumn(columnLabel), x);
    }

    @Override
    public void updateTimestamp(String columnLabel, Timestamp x) {
        resultSet.updateTimestamp(findColumn(columnLabel), x);
    }

    @Override
    public void updateAsciiStream(String columnLabel, InputStream x, int length) {
        resultSet.updateAsciiStream(findColumn(columnLabel), x, length);
    }

    @Override
    public void updateBinaryStream(String columnLabel, InputStream x, int length) {
        resultSet.updateBinaryStream(findColumn(columnLabel), x, length);
    }

    @Override
    public void updateCharacterStream(String columnLabel, Reader reader, int length) {
        resultSet.updateCharacterStream(findColumn(columnLabel), reader, length);
    }

    @Override
    public void updateObject(String columnLabel, Object x, int scaleOrLength) {
        resultSet.updateObject(findColumn(columnLabel), x, scaleOrLength);
    }

    @Override
    public void updateObject(String columnLabel, Object x) {
        resultSet.updateObject(findColumn(columnLabel), x);
    }

    @Override
    public void insertRow() throws JannexException {
        resultSet.insertRow();
    }

    @Override
    public void updateRow() throws JannexException {
        resultSet.updateRow();
    }

    @Override
    public void deleteRow() throws JannexException {
        resultSet.deleteRow();
    }

    @Override
    public void refreshRow() throws JannexException {
        resultSet.refreshRow();
    }

    @Override
    public void cancelRowUpdates() throws JannexException {
        resultSet.cancelRowUpdates();
    }

    @Override
    public void moveToInsertRow() throws JannexException {
        resultSet.moveToInsertRow();
    }

    @Override
    public void moveToCurrentRow() throws JannexException {
        resultSet.moveToCurrentRow();
    }

    @Override
    public JxStatement getStatement() throws JannexException {
        return resultSet.getStatement();
    }

    @Override
    public void updateNull(int columnIndex) {
        resultSet.updateNull(columns[columnIndex-1]);
    }

    @Override
    public void updateBoolean(int columnIndex, boolean x) {
        resultSet.updateBoolean(columns[columnIndex-1], x);
    }

    @Override
    public void updateByte(int columnIndex, byte x) {
        resultSet.updateByte(columns[columnIndex-1], x);
    }

    @Override
    public void updateShort(int columnIndex, short x) {
        resultSet.updateShort(columns[columnIndex-1], x);
    }

    @Override
    public void updateInt(int columnIndex, int x) {
        resultSet.updateInt(columns[columnIndex-1], x);
    }

    @Override
    public void updateLong(int columnIndex, long x) {
        resultSet.updateLong(columns[columnIndex-1], x);
    }

    @Override
    public void updateFloat(int columnIndex, float x) {
        resultSet.updateFloat(columns[columnIndex-1], x);
    }

    @Override
    public void updateDouble(int columnIndex, double x) {
        resultSet.updateDouble(columns[columnIndex-1], x);
    }

    @Override
    public void updateBigDecimal(int columnIndex, BigDecimal x) {
        resultSet.updateBigDecimal(columns[columnIndex-1], x);
    }

    @Override
    public void updateString(int columnIndex, String x) {
        resultSet.updateString(columns[columnIndex-1], x);
    }

    @Override
    public void updateBytes(int columnIndex, byte[] x) {
        resultSet.updateBytes(columns[columnIndex-1], x);
    }

    @Override
    public void updateDate(int columnIndex, Date x) {
        resultSet.updateDate(columns[columnIndex-1], x);
    }

    @Override
    public void updateTime(int columnIndex, Time x) {
        resultSet.updateTime(columns[columnIndex-1], x);
    }

    @Override
    public void updateTimestamp(int columnIndex, Timestamp x) {
        resultSet.updateTimestamp(columns[columnIndex-1], x);
    }

    @Override
    public void updateAsciiStream(int columnIndex, InputStream x, int length) {
        resultSet.updateAsciiStream(columns[columnIndex-1], x, length);
    }

    @Override
    public void updateBinaryStream(int columnIndex, InputStream x, int length) {
        resultSet.updateBinaryStream(columns[columnIndex-1], x, length);
    }

    @Override
    public void updateCharacterStream(int columnIndex, Reader x, int length) {
        resultSet.updateCharacterStream(columns[columnIndex-1], x, length);
    }

    @Override
    public void updateObject(int columnIndex, Object x, int scaleOrLength) {
        resultSet.updateObject(columns[columnIndex-1], x, scaleOrLength);
    }

    @Override
    public void updateObject(int columnIndex, Object x) {
        resultSet.updateObject(columns[columnIndex-1], x);
    }

    @Override
    public void updateNull(String columnLabel) {
        resultSet.updateNull(findColumn(columnLabel));
    }

    @Override
    public Reader getCharacterStream(String columnLabel) {
        return resultSet.getCharacterStream(findColumn(columnLabel));
    }

    @Override
    public BigDecimal getBigDecimal(int columnIndex) {
        return resultSet.getBigDecimal(columns[columnIndex-1]);
    }

    @Override
    public BigDecimal getBigDecimal(String columnLabel) {
        return resultSet.getBigDecimal(findColumn(columnLabel));
    }

    @Override
    public boolean isBeforeFirst() throws JannexException {
        return resultSet.isBeforeFirst();
    }

    @Override
    public boolean isAfterLast() throws JannexException {
        return resultSet.isAfterLast();
    }

    @Override
    public boolean isFirst() throws JannexException {
        return resultSet.isFirst();
    }

    @Override
    public boolean isLast() throws JannexException {
        return resultSet.isLast();
    }

    @Override
    public void beforeFirst() throws JannexException {
        resultSet.beforeFirst();
    }

    @Override
    public void afterLast() throws JannexException {
        resultSet.afterLast();
    }

    @Override
    public boolean first() throws JannexException {
        return resultSet.first();
    }

    @Override
    public boolean last() throws JannexException {
        return resultSet.last();
    }

    @Override
    public int getRow() throws JannexException {
        return resultSet.getRow();
    }

    @Override
    public boolean absolute(int row) throws JannexException {
        return resultSet.absolute(row);
    }

    @Override
    public boolean relative(int rows) throws JannexException {
        return resultSet.relative(rows);
    }

    @Override
    public boolean previous() throws JannexException {
        return resultSet.previous();
    }

    @Override
    public void setFetchDirection(int direction) throws JannexException {
        resultSet.setFetchDirection(direction);
    }

    @Override
    public int getFetchDirection() throws JannexException {
        return resultSet.getFetchDirection();
    }

    @Override
    public void setFetchSize(int rows) throws JannexException {
        resultSet.setFetchSize(rows);
    }

    @Override
    public int getFetchSize() throws JannexException {
        return resultSet.getFetchSize();
    }

    @Override
    public int getType() throws JannexException {
        return resultSet.getType();
    }

    @Override
    public int getConcurrency() throws JannexException {
        return resultSet.getConcurrency();
    }

    @Override
    public boolean rowUpdated() throws JannexException {
        return resultSet.rowUpdated();
    }

    @Override
    public boolean rowInserted() throws JannexException {
        return resultSet.rowInserted();
    }

    @Override
    public boolean rowDeleted() throws JannexException {
        return resultSet.rowDeleted();
    }

    @Override
    public byte getByte(String columnLabel) {
        return resultSet.getByte(findColumn(columnLabel));
    }

    @Override
    public short getShort(String columnLabel) {
        return resultSet.getShort(findColumn(columnLabel));
    }

    @Override
    public int getInt(String columnLabel) {
        return resultSet.getInt(findColumn(columnLabel));
    }

    @Override
    public long getLong(String columnLabel) {
        return resultSet.getLong(findColumn(columnLabel));
    }

    @Override
    public float getFloat(String columnLabel) {
        return resultSet.getFloat(findColumn(columnLabel));
    }

    @Override
    public double getDouble(String columnLabel) {
        return resultSet.getDouble(findColumn(columnLabel));
    }

    @Override
    @Deprecated
    @SuppressWarnings("deprecation")
    public BigDecimal getBigDecimal(String columnLabel, int scale) {
        return resultSet.getBigDecimal(findColumn(columnLabel), scale);
    }

    @Override
    public byte[] getBytes(String columnLabel) {
        return resultSet.getBytes(findColumn(columnLabel));
    }

    @Override
    public Date getDate(String columnLabel) {
        return resultSet.getDate(findColumn(columnLabel));
    }

    @Override
    public Time getTime(String columnLabel) {
        return resultSet.getTime(findColumn(columnLabel));
    }

    @Override
    public Timestamp getTimestamp(String columnLabel) {
        return resultSet.getTimestamp(findColumn(columnLabel));
    }

    @Override
    public InputStream getAsciiStream(String columnLabel) {
        return resultSet.getAsciiStream(findColumn(columnLabel));
    }

    @Override
    @Deprecated
    @SuppressWarnings("deprecation")
    public InputStream getUnicodeStream(String columnLabel) {
        return resultSet.getUnicodeStream(findColumn(columnLabel));
    }

    @Override
    public InputStream getBinaryStream(String columnLabel) {
        return resultSet.getBinaryStream(findColumn(columnLabel));
    }

    @Override
    public SQLWarning getWarnings() throws JannexException {
        return resultSet.getWarnings();
    }

    @Override
    public void clearWarnings() throws JannexException {
        resultSet.clearWarnings();
    }

    @Override
    public String getCursorName() throws JannexException {
        return resultSet.getCursorName();
    }

    @Override
    public Object getObject(int columnIndex) {
        return resultSet.getObject(columns[columnIndex-1]);
    }

    @Override
    public Object getObject(String columnLabel) {
        return resultSet.getObject(findColumn(columnLabel));
    }

    @Override
    public Reader getCharacterStream(int columnIndex) {
        return resultSet.getCharacterStream(columns[columnIndex-1]);
    }

    @Override
    @Deprecated
    @SuppressWarnings("deprecation")
    public InputStream getUnicodeStream(int columnIndex) {
        return resultSet.getUnicodeStream(columns[columnIndex-1]);
    }

    @Override
    public InputStream getBinaryStream(int columnIndex) {
        return resultSet.getBinaryStream(columns[columnIndex-1]);
    }

    @Override
    public String getString(String columnLabel) {
        return resultSet.getString(findColumn(columnLabel));
    }

    @Override
    public boolean getBoolean(String columnLabel) {
        return resultSet.getBoolean(findColumn(columnLabel));
    }

}
